#!/usr/bin/env python3
# -*- coding: utf-8 -*
# Time :2024-06-15 9:10
# @Author: baiping
import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

class UseBrowser:
    driver=None
    def __init__(self,name='chrome',path='chromedriver.exe'):
        try:
            if name.lower() == 'chrome':
                service_path = Service(path)
                self.driver = webdriver.Chrome(service=service_path)
                self.driver.implicitly_wait(5)
                self.driver.maximize_window()
                UseBrowser.driver=self.driver
            elif name.lower() == 'edge':
                service_path = Service(path)
                self.driver = webdriver.Edge(service=service_path)
                self.driver.implicitly_wait(5)
                self.driver.maximize_window()
                UseBrowser.driver = self.driver
            elif name.lower() == 'firefox':
                pass

            else:
                print('support: chrome,edge,firefox')

        except Exception as e:
            print(f'browser init error:{e}')

    @classmethod
    def quit(cls):
        time.sleep(2)
        cls.driver.quit()


if __name__=='__main__':
    ub = UseBrowser()
    ub.quit()